package cn.org.zych.diyjdkproxy;

import cn.org.zych.service.LogService;

import java.lang.reflect.Method;

/**
 * @ClassName:
 * @Description:
 * @Auther: zhouych
 * @Date: 2019/3/18 11:18
 */
public class DIYLogProxy implements DIYInvocationHandler {


    private LogService logService = new LogService();

    private Object object = null;

    public Object getInstance(Object object){
        this.object = object;
        return DIYProxy.newProxyInstance(new DIYClassLoader(),
                object.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        logService.before();
        Object result = method.invoke(object,args);
        logService.after();
        return result;
    }


}
